package util

import (
	"regexp"
	"strings"
)

// UnderlineToCamel 下划线转驼峰
func UnderlineToCamel(str string) string {
	reg := regexp.MustCompile(`_([a-z])`)
	result := reg.ReplaceAllStringFunc(str, func(s string) string {
		return strings.ToUpper(strings.TrimLeft(s, "_"))
	})

	return result
}

// UnderlineLowerFirstToCamel 下划线转驼峰但是首字母小写
func UnderlineLowerFirstToCamel(word string) string {
	camel := UnderlineToCamel(word)

	return strings.ToLower(camel[:1]) + camel[1:]
}

// CamelToUnderline 驼峰转下划线
func CamelToUnderline(camel string) string {
	// 将驼峰命名转换为小写字母加下划线
	underline := ""
	for i, char := range camel {
		if i > 0 && char >= 'A' && char <= 'Z' {
			underline += "_"
		}
		underline += string(char)
	}
	return strings.ToLower(underline)
}

func IsCamel(str string) bool {
	// 判断字符串是否包含大写字母
	if strings.ContainsAny(str, "_") {
		return false
	}
	return true
}
